<template>
  <div class="common-layout">
    <el-dialog v-model="showFlag" title="行情记录添加">
      <el-form ref="formRef" :model="form" :rules="rules">
        <el-form-item label="名称" :label-width="120" prop="name">
          <el-input v-model="form.name" autocomplete="off" />
        </el-form-item>
        <el-form-item label="次级回升" :label-width="120" prop="secondary_upward_trend">
          <el-input v-model="form.secondary_upward_trend" type="number" autocomplete="off" />
        </el-form-item>
        <el-form-item label="自然回升" :label-width="120" type="number" prop="auto_upward_trend">
          <el-input v-model="form.auto_upward_trend" autocomplete="off" />
        </el-form-item>
        <el-form-item label="上升趋势" :label-width="120" type="number" prop="upward_trend">
          <el-input v-model="form.upward_trend" autocomplete="off" />
        </el-form-item>
        <el-form-item label="下降趋势" :label-width="120" type="number" prop="decline_trend">
          <el-input v-model="form.decline_trend" autocomplete="off" />
        </el-form-item>
        <el-form-item label="自然回撤" :label-width="120" type="number" prop="auto_decline_trend">
          <el-input v-model="form.auto_decline_trend" autocomplete="off" />
        </el-form-item>
        <el-form-item label="次级回撤" :label-width="120" type="number" prop="secondary_decline_trend">
          <el-input v-model="form.secondary_decline_trend" autocomplete="off" />
        </el-form-item>
        <el-form-item label="涨幅" :label-width="120" prop="scope">
          <el-input v-model="form.scope" autocomplete="off" />
        </el-form-item>
        <el-form-item label="板块" :label-width="120" prop="sector">
          <el-input v-model="form.sector" autocomplete="off" />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="colse">取消</el-button>
          <el-button type="primary" @click="submit"> 保存 </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts">
import advancedFormat from 'dayjs/plugin/advancedFormat'
import { defineComponent, reactive, ref } from 'vue'
import { addRecord } from '@/api/user'
import { ElMessage, FormInstance, FormRules } from 'element-plus'
import { fa } from 'element-plus/es/locale'
export default defineComponent({
  setup() {
    const showFlag = ref(false)
    const form = reactive({
      name: '',
      secondary_upward_trend: '',
      auto_upward_trend: '',
      upward_trend: '',
      decline_trend: '',
      auto_decline_trend: '',
      secondary_decline_trend: '',
      scope: '0%',
      sector: '',
    })
    const rules = reactive<FormRules>({
      name: [{ required: true, message: '请填写名称', trigger: 'blur' }],
      // secondary_upward_trend: [{ type: 'number', message: '请输入数字' }],
      // auto_upward_trend: [{ type: 'number', message: '请输入数字' }],
      // upward_trend: [{ type: 'number', message: '请输入数字' }],
      // decline_trend: [{ type: 'number', message: '请输入数字' }],
      // auto_decline_trend: [{ type: 'number', message: '请输入数字' }],
      // secondary_decline_trend: [{ type: 'number', message: '请输入数字' }],
      scope: [{ required: true, message: '请填写涨幅', trigger: 'blur' }],
      sector: [{ required: true, message: '请填写板块', trigger: 'blur' }],
    })
    const formRef = ref<FormInstance>()
    const colse = () => {
      showFlag.value = false
    }
    const submit = async () => {
      console.log(formRef, 2222)
      if (!formRef.value) return
      await formRef.value.validate(async valid => {
        if (valid) {
          let datas = await addRecord(form)
          if (datas.state === 200) {
            ElMessage.success(datas.msg)
            showFlag.value = false
          }
        } else {
          console.log('error submit!')
          return false
        }
      })
    }
    return { form, showFlag, colse, rules, submit, formRef }
  },
})
</script>

<style scoped lang="less"></style>
